package com.auth.user;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Expression;
import org.hibernate.criterion.Restrictions;
import com.langsotech.base.Page;
import com.langsotech.methods.db.DbMethods;
public class MyTAuthUserLogic {
	public static java.util.List queryAll(String dbName, com.auth.TAuthUser obj, Page page){
		Session session = DbMethods.getSession(dbName);
		Criteria cri = session.createCriteria(obj.getClass());
		if(obj.getId() != null)
			cri.add( Restrictions.like("id", "%" + obj.getId() + "%") );
		if(obj.getName() != null)
			cri.add( Restrictions.like("name", "%" + obj.getName() + "%") );
		if(obj.getSex() != 0)
			cri.add( Restrictions.eq("sex", obj.getSex()) );
		if(obj.getDepartmentId() != null && !obj.getDepartmentId().equals("0"))
			cri.add( Restrictions.eq("departmentId", obj.getDepartmentId()) );
		if(obj.getRoleId() != null && !obj.getRoleId().equals("0"))
			cri.add( Restrictions.eq("roleId", obj.getRoleId()) );
		return DbMethods.getResult(cri, page);
	}
	public static java.util.List testQueryAll(String dbName, Object obj, Page page){
		Session session = DbMethods.getSession(dbName);
		Criteria cri = session.createCriteria(obj.getClass());
		java.lang.reflect.Field[] fields = obj.getClass().getFields();
		for(java.lang.reflect.Field field : fields){
			cri.add( Restrictions.eq(field.getName(), obj) );
		}
		/*if(obj.getId() != null)
			cri.add( Restrictions.like("id", "%" + obj.getId() + "%") );
		if(obj.getName() != null)
			cri.add( Restrictions.like("name", "%" + obj.getName() + "%") );
		if(obj.getSex() != 0)
			cri.add( Restrictions.eq("sex", obj.getSex()) );
		if(obj.getDepartmentId() != null && !obj.getDepartmentId().equals("0"))
			cri.add( Restrictions.eq("departmentId", obj.getDepartmentId()) );
		if(obj.getRoleId() != null && !obj.getRoleId().equals("0"))
			cri.add( Restrictions.eq("roleId", obj.getRoleId()) );*/
		return DbMethods.getResult(cri, page);
	}
}
